package com.ifast.utils;

import java.util.Properties;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;

public class YamlPropertiesUtil {

	public static Properties properties = null;
	static {

		// https://hacpai.com/article/1534999477139
		YamlPropertiesFactoryBean yamlMapFactoryBean = new YamlPropertiesFactoryBean();
		// 可以加载多个 yml 文件
		yamlMapFactoryBean.setResources(new ClassPathResource("application.yml"));
		properties = yamlMapFactoryBean.getObject();
		String active = properties.getProperty("spring.profiles.active");
		yamlMapFactoryBean.setResources(new ClassPathResource("application.yml"), //
				new ClassPathResource("application-" + active + ".yml")//
		);
		properties = yamlMapFactoryBean.getObject();

	}

	public static String getProperty(String key) {
		return properties.getProperty(key);
	}

	public static void main(String[] args) {
		System.out.println(getProperty("weixin.filePath"));
	}

}
